package com.well.register.console.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.well.register.console.dao.UserMapper;
import com.well.register.console.domain.User;
import com.well.register.console.service.UserService;
import com.well.register.console.util.CodeInfo;
import com.well.register.console.util.RpcResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * user service impl
 * </p>
 *
 * @author weedo
 * @since 2022/7/31
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;
    @Override
    public RpcResponse getUserByUsernamePassword(String username, String password) {
        User user = userMapper.getUserByUsernamePassword(username, password);
        if (user == null) {
        return  RpcResponse.fail(CodeInfo.USER_NOT_FOUND);
        }
        return RpcResponse.ok(user);
    }

    @Override
    public int getUser(String accessKey) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("access_key", accessKey);
        return this.count(wrapper);
    }
}

